# event.py
from app import db
from datetime import date

class Event(db.Model):
    __tablename__ = 'event'
    # 使用复合主键
    pid = db.Column(db.String(20), primary_key=True)
    pidtime = db.Column(db.Date, primary_key=True)  # 使用 Date 类型
    
    # 移除 id 字段
    tname1 = db.Column(db.String(50), nullable=False)
    tname2 = db.Column(db.String(50), nullable=False)
    league = db.Column(db.String(50), nullable=False)

    def to_dict(self):
        """转换为字典，方便接口返回"""
        return {
            'pid': self.pid,
            'tname1': self.tname1,
            'tname2': self.tname2,
            'league': self.league,
            'pidtime': self.pidtime.isoformat() if self.pidtime else None
        }